cmake_minimum_required(VERSION 3.18.1)

project("nativelib")

file(GLOB NATIVE_SRC src/main/cpp/*.cpp)
# 生成 nativelib 库
add_library( # Sets the name of the library.
             nativelib
             SHARED
             nativelib.cpp )

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
# 添加链接库
target_link_libraries( # Specifies the target library.
                       nativelib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

# 指定生成 JNI 头文件的路径
set(JNI_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../src/main/jni/com_example_nativelib_HelloNative.h)

# 添加生成 JNI 头文件的指令
add_custom_command(
        OUTPUT ${JNI_HEADERS}
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../..../com/example/nativelib/HelloNative.kt
        COMMAND javac -h ${CMAKE_CURRENT_SOURCE_DIR}/../src/main/jni ${CMAKE_CURRENT_SOURCE_DIR}/../../..../com/example/nativelib/HelloNative.kt
        COMMENT "Generating JNI headers"
)

add_custom_target(jni_header ALL DEPENDS ${JNI_HEADERS})
